package com.ruoyi.school.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.school.domain.Text;
import com.ruoyi.school.service.ITextService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 一班Controller
 * 
 * @author Francis
 * @date 2025-07-22
 */
@RestController
@RequestMapping("/school/cls01")
public class TextController extends BaseController
{
    @Autowired
    private ITextService textService;

    /**
     * 查询一班列表
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:list')")
    @GetMapping("/list")
    public TableDataInfo list(Text text)
    {
        startPage();
        List<Text> list = textService.selectTextList(text);
        return getDataTable(list);
    }

    /**
     * 导出此班列表
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:export')")
    @Log(title = "一班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Text text)
    {
        List<Text> list = textService.selectTextList(text);
        ExcelUtil<Text> util = new ExcelUtil<Text>(Text.class);
        util.exportExcel(response, list, "一班数据");
    }

    /**
     * 获取一班详细信息
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(textService.selectTextById(id));
    }

    /**
     * 新增一班
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:add')")
    @Log(title = "一班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Text text)
    {
        return toAjax(textService.insertText(text));
    }

    /**
     * 修改一班
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:edit')")
    @Log(title = "一班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Text text)
    {
        return toAjax(textService.updateText(text));
    }

    /**
     * 删除一班
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:remove')")
    @Log(title = "一班", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(textService.deleteTextByIds(ids));}

    /**
     * 根据成绩降序排序查询学生列表
     * @param
     * @return
     */
    @PreAuthorize("@ss.hasPermi('school:cls01:sort')")
    @GetMapping("/sortByGrade")
    public AjaxResult sortByGrade() {
        // 直接获取全部数据并排序（不启用分页）
        List<Text> list = textService.selectTextListSortedByGradeDesc();
        return AjaxResult.success(list); // 返回完整列表
    }



//end
}
